package com.chuangjiangx.member.score.ddd.query;

import com.chuangjiangx.member.score.dao.mapper.InMbrScoreGrandTotalRuleMapper;
import com.chuangjiangx.member.score.dao.model.InMbrScoreGrandTotalRule;
import com.chuangjiangx.member.score.dao.model.InMbrScoreGrandTotalRuleExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 积分累计规则
 */
@Component
public class MbrScoreGrandTotalRuleQuery {

    @Autowired
    private InMbrScoreGrandTotalRuleMapper inMbrScoreGrandTotalRuleMapper;

    /**
     * 根据商户id查询积分累计规则
     *
     * @param merchantId 商户id
     * @return InMbrScoreGrandTotalRule
     */
    public InMbrScoreGrandTotalRule queryScoreGrandTotalRuleByMerchantId(Long merchantId) {

        InMbrScoreGrandTotalRuleExample example = new InMbrScoreGrandTotalRuleExample();
        example.createCriteria()
                .andMerchantIdEqualTo(merchantId);
        List<InMbrScoreGrandTotalRule> list = inMbrScoreGrandTotalRuleMapper.selectByExample(example);
        return list.isEmpty() ? null : list.get(0);
    }

}
